﻿<?php

      /*<----调用翻页功能函数---->*/

        /*定义变量接住从地址栏传来的数值p*/



        if(empty($_GET['p'])){
            $page = 1;
        }else{
            $page = $_GET['p'];
        }

         $rowse=1;

         /*偏移量=（当前页码数-1）* 每页行数 */
         $offset =($page-1)*$rowse;

        /*调用翻页函数*/
         $page_str=getpage($link,$page,$rowse);

      /*<----/调用翻页功能函数---->*/

         /*编写查询语句*/
        // $sql = "select * from `test`.`news` where `endble`=1 order by `id` desc limit $offset,$rowse";

          // $sql="select `news`.*,`cate`.`name` from `news`  inner join `cate`  on `news`.`type`=`cate`.`id` where `news`.`endble`=0";


          //内联简写
          $sql="select `news`.*,`cate`.`name` from `news`,`cate` where `news`.`type`=`cate`.`id` and `news`.`endble`=1 order by `id` desc limit $offset,$rowse";


         /*执行查询数据库语句，将刚刚提交的新闻数据查询出来用变量接住*/
         $rsl = mysqli_query($link,$sql);

         /*$date返回一个结果集，通过循环从结果集取真实数据
            原理，条件为真的情况：1有值的变量、非零的正数、true;

            while 循环
         */
            $date = array();
            while($dd = mysqli_fetch_assoc($rsl)){
            $date[] = $dd;

        }
       // print_r($date);

        // print_r($date);die;

   /*<----无刷新编辑功能请求---->*/
       /*判断是否是ajax请求*/
                           // HTTP_X_REQUESTED_WITH
        if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

/*+1行功能*/
              if(!empty($_GET['ss'])){

                  $title = $_GET['title'];
                  $content = $_GET['content'];
                  $type = $_GET['type'];

                  $sql = "insert into `news` (`title`,`content`,`type`) values('$title','$content','$type')";
                  mysqli_query($link,$sql);
                  if($rows>0){echo "<script>alert('删除成功');location.href='index.php?c=news&&a=list&&admin=1'</script>";}
             die;
              }



/*+1行功能*/

              /*点击审核状态功能*/
              if(!empty($_GET['id'])){

                $id =  $_GET['id'];

                if($_GET['s']==0){
                   $sql = "update `news` set `statius`='1' where `id`=$id";
                   mysqli_query($link,$sql);
                   echo mysqli_affected_rows($link);
                }else{
                  $sql = "update `news` set `statius`='0' where `id`=$id";
                   mysqli_query($link,$sql);
                   echo mysqli_affected_rows($link);
                }
                die;
              }


              /*ajax提交类型为get*/
              if(!empty($_GET['p'])){


                  /*将要返回的数据放到一个数组的不同下标*/
                  $jk['data'] =$date;
                  $jk['page_str'] =$page_str;


                  /*将需要数据进行返回 并将Php的数组格式转化成js的json格式给html前台使用*/
                  echo (json_encode($jk));
                  die;
              }

              /*ajax提交类型为post*/
             if(!empty($_POST)){


                     /*正在修改行id*/
                     $id = $_POST['id'];

                     /*修改完后的内容*/
                     $content = $_POST['uval'];

                     /*字段名*/
                     $co = $_POST['co'];

                     $sql ="update `news` set `$co`='$content' where `id`=$id" ;

                     mysqli_query($link,$sql);

                     /*获取sql执行后，影响的行数*/
                     $math = mysqli_affected_rows($link);

                     /*反回到前台ajax的回调函数中*/
                     echo $math;

                     die;
             }

        }
        /*<----/无刷新编辑功能请求---->*/


		include(CON_VIEW.$q.'/common.html');
?>